﻿
@{
    ViewData["Title"] = "GroupEdit";
}


@using ViewModel.admin
@model sys_admin_groupVm


<div class="weadmin-body" id="divEdit">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="we-red">*</span>角色名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="gname" name="gname" v-model="model.gname" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="we-red">*</span>将会成为您唯一的登入名
            </div>
        </div>
        <div class="layui-form-item">
            @Html.Raw(ViewBag.Menus)
        </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" v-if="model.id==0" lay-filter="add" type="button" lay-submit="">增加</button>
                <button class="layui-btn" v-else lay-filter="add" type="button" lay-submit="">修改</button>
            </div>
    </form>
</div>

@section Scripts
    {
    <script type="text/javascript">
            var model=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model))

            var vm = new Vue({
                el: '#divEdit',
                data: {
                   model:model
                },
                methods: {
                    submit: function () {

                        //// 获得frame索引
                        //var index = parent.layer.getFrameIndex(window.name);
                        ////关闭当前frame
                        //parent.layer.close(index);
                    }
                }
            })


            layui.extend({
                admin: '{/}../../static/js/admin'
            });
            layui.use(['form', 'layer', 'admin'], function () {
                    var form = layui.form;

                form.on('submit(add)', function (data) {
                    vm.model.limits =  String(tableCheck.getData());
                    $.post("@Url.Action("GroupEditAction")", { model: JSON.stringify(vm.model) }, function (data) {
                            layer.msg('操作成功！', {
                                icon: 1
                            }, function () {
                                parent.location.href = parent.location.href;
                                });
                        })
                    //这样子点击就会触发该验证方法.
                    return false;
                })
        })

        $(function () {
            var arr = model.limits.split(',');
            for (var i = 0; i < arr.length; i++) {
                $(".layui-form-checkbox[data-id=" + arr[i] + "]").addClass("layui-form-checked");
            }
        })


    </script>
}
